﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sock
{
    class ManageServerClients
    {
        Dictionary<string, ClientServerThread> clients = new Dictionary<string, ClientServerThread>();
        public void addClient(string key , ClientServerThread value) 
        {
            clients.Add(key, value);
        }
        public bool alreadyClient(string key)
        {
           return clients.Keys.Contains(key);
        }

        public void removeClient(string key) {
            clients.Remove(key);
        }
        public void updateName(string lname,string nname)
        {
            if (clients.ContainsKey(lname)) {
                ClientServerThread cst=null;
                cst = clients[lname];
                clients.Remove(lname);
                clients.Add(nname, cst);
                //removeClient(lname);
                //addClient(nname, cst);
            }
        }

        public string getClients(string exceptKey) {
            string final="";
            foreach (string r in clients.Keys) {
                if(!r.Equals(exceptKey))
                    final += r+" ";
            }
            return final;
        }
        public ClientServerThread getClient(string cl)
        {
            if (clients.ContainsKey(cl))
            {
                return clients[cl];
            }
            return null;
        }
    }
}
